package com.mf.ergate.controller.bo.pt;

import com.mf.ergate.api.bo.pt.PtOrderHelpBuyRemoteService;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderHelpBuyCreateDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderHelpBuyDeleteDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderHelpBuyQueryDto;
import com.mf.ergate.api.bo.pt.model.dto.PtOrderHelpBuyUpdateDto;
import com.mf.ergate.api.bo.pt.model.vo.PtOrderHelpBuyVo;
import com.mf.ergate.common.utils.MfBeanUtils;
import com.mf.ergate.domain.model.bo.pt.PtOrderHelpBuyEntity;
import com.mf.ergate.service.bo.pt.PtOrderHelpBuyService;
import com.mf.framework.common.model.Page;
import com.mf.framework.common.model.RemotePage;
import com.mf.framework.common.model.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 跑腿订单帮买Controller
 * User: zhaoming
 * DateTime: 2019-01-28
 * To change this template use File | Settings | File Templates.
 */
@RestController
public class PtOrderHelpBuyController implements PtOrderHelpBuyRemoteService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private PtOrderHelpBuyService ptOrderHelpBuyService;

    /**
     * 新增
     * @param ptOrderHelpBuyCreateDto 跑腿订单帮买新增Dto
     * @return 跑腿订单帮买
     */
    public Result<PtOrderHelpBuyVo> insert(@RequestBody PtOrderHelpBuyCreateDto ptOrderHelpBuyCreateDto) {
        PtOrderHelpBuyEntity ptOrderHelpBuyEntity = MfBeanUtils.copyObject(ptOrderHelpBuyCreateDto, PtOrderHelpBuyEntity.class);
        ptOrderHelpBuyEntity = ptOrderHelpBuyService.insert(ptOrderHelpBuyEntity);
        PtOrderHelpBuyVo ptOrderHelpBuyVo = MfBeanUtils.copyObject(ptOrderHelpBuyEntity, PtOrderHelpBuyVo.class);
        return new Result<>(ptOrderHelpBuyVo);
    }

    /**
     * 根据唯一编号更新
     * @param ptOrderHelpBuyUpdateDto 跑腿订单帮买更新Dto
     * @return 执行结果
     */
    public Result<Boolean> updateByUniqueNo(@RequestBody PtOrderHelpBuyUpdateDto ptOrderHelpBuyUpdateDto) {
        PtOrderHelpBuyEntity ptOrderHelpBuyEntity = MfBeanUtils.copyObject(ptOrderHelpBuyUpdateDto, PtOrderHelpBuyEntity.class);
        Boolean flag = ptOrderHelpBuyService.updateByUniqueNo(ptOrderHelpBuyEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号删除(逻辑删除)
     * @param ptOrderHelpBuyDeleteDto 跑腿订单帮买删除Dto
     * @return 结果集
     */
    public Result<Boolean> deleteByUniqueNo(@RequestBody PtOrderHelpBuyDeleteDto ptOrderHelpBuyDeleteDto){
        PtOrderHelpBuyEntity ptOrderHelpBuyEntity = MfBeanUtils.copyObject(ptOrderHelpBuyDeleteDto, PtOrderHelpBuyEntity.class);
        Boolean flag = ptOrderHelpBuyService.deleteByUniqueNo(ptOrderHelpBuyEntity);
        return new Result<>(flag);
    }

    /**
     * 根据唯一编号查询
     * @param uniqueNo 唯一编号
     * @return 跑腿订单帮买
     */
    public Result<PtOrderHelpBuyVo> selectByUniqueNo(@RequestBody String uniqueNo) {
        PtOrderHelpBuyEntity ptOrderHelpBuyEntity = ptOrderHelpBuyService.selectByUniqueNo(uniqueNo);
        PtOrderHelpBuyVo ptOrderHelpBuyVo = MfBeanUtils.copyObject(ptOrderHelpBuyEntity, PtOrderHelpBuyVo.class);
        return new Result<>(ptOrderHelpBuyVo);
    }

    /**
     * 根据条件查询
     * @param ptOrderHelpBuyQueryDto 跑腿订单帮买查询Dto
     * @return 跑腿订单帮买列表
     */
    public Result<List<PtOrderHelpBuyVo>> selectByCondition(@RequestBody PtOrderHelpBuyQueryDto ptOrderHelpBuyQueryDto) {
        List<PtOrderHelpBuyEntity> ptOrderHelpBuyEntities = ptOrderHelpBuyService.selectByCondition(ptOrderHelpBuyQueryDto);
        List<PtOrderHelpBuyVo> ptOrderHelpBuyVos = MfBeanUtils.copyList(ptOrderHelpBuyEntities, PtOrderHelpBuyVo.class);
        return new Result<>(ptOrderHelpBuyVos);
    }

    /**
     * 根据条件查询数量
     * @param ptOrderHelpBuyQueryDto 跑腿订单帮买查询Dto
     * @return 数量
     */
    public Result<Integer> selectCount(@RequestBody PtOrderHelpBuyQueryDto ptOrderHelpBuyQueryDto) {
        return new Result<>(ptOrderHelpBuyService.selectCount(ptOrderHelpBuyQueryDto));
    }

    /**
     * 根据条件分页查询
     * @param remotePage 远程分页对象
     * @return 跑腿订单帮买分页列表
     */
    public Result<Page<PtOrderHelpBuyVo>> selectPage(@RequestBody RemotePage<PtOrderHelpBuyQueryDto> remotePage){
        Page<PtOrderHelpBuyEntity> ptOrderHelpBuyEntityPage = ptOrderHelpBuyService.selectPage(remotePage.getPage(), remotePage.getObj());
        Page<PtOrderHelpBuyVo> page = MfBeanUtils.copyPage(ptOrderHelpBuyEntityPage, PtOrderHelpBuyVo.class);
        return new Result<>(page);
    }

}